import { publishComposite } from 'meteor/reywood:publish-composite';
import {user,image,apply,friends, messages,indexMsg,circleInf,circleStatus, group, groupUser} from '../../imports/api/collections/index';

//获取图片信息
publishComposite('imgList',{
    find:function(){
        return image.find({})
    }
})
// 获取用户信息
publishComposite('userInf',{
    find:function(){
        return user.find({})
    },
    children:[
        {
            find(user){
                return image.find({_id:user.avatarId})
            }
        },
        {
            find(user){
                return apply.find({A_UserID:user._id})
            }
        },
        {
            find(user){
                return friends.find({F_UserID:user._id})
            }
        },
        {
            find(user){
                return messages.find({M_ToUserID:user._id})
            },
        },
        {
            find(user){
                return indexMsg.find({I_UserId:user._id})
            },
            children:[{
                find(index){
                    return group.find({_id:index.I_OtherId})
                },
                children:[{
                    find(group){
                        return groupUser.find({gid:group._id})
                    }
                },
                {
                    find(group){
                        return image.find({_id:group.g_avatarId})
                    }
                },
                {
                    find(group){
                        return messages.find({M_GroupId:group._id})
                    }
                }]
            }]
        },
        {
            find(user){
                return circleInf.find({uid:user._id})
            }
        },
        {
            find(user){
                return circleStatus.find({fid:user._id})
            }
        }
    ]
})
